package nk.com.settingdemo;

import android.content.ComponentName;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
        findViewById(R.id.btn3).setOnClickListener(this);
        findViewById(R.id.btn4).setOnClickListener(this);
        findViewById(R.id.btn5).setOnClickListener(this);
        findViewById(R.id.btn6).setOnClickListener(this);
        findViewById(R.id.btn7).setOnClickListener(this);
        findViewById(R.id.btn8).setOnClickListener(this);
/*
        //带返回部分
        findViewById(R.id.btn9).setOnClickListener(this);
        findViewById(R.id.btn10).setOnClickListener(this);
        findViewById(R.id.btn11).setOnClickListener(this);      */
    }

    /**
     * 简单封装一下Intent跳转，懒得多些代码 ...
     **/
    void toIntent(String action) {
    /*  Intent intent = new Intent(action);
        startActivity(intent);
    */
        Intent it = new Intent(action);
        it.putExtra("extra_prefs_show_button_bar", true);
        it.putExtra("extra_prefs_set_back_text", "返回");
        it.putExtra("extra_prefs_set_next_text", "完成");
        startActivity(it);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                toIntent(Settings.ACTION_SETTINGS);
                break;
            case R.id.btn2:
                toIntent(Settings.ACTION_WIFI_SETTINGS);
                break;
            case R.id.btn3:
                toIntent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
                break;
            case R.id.btn4:
                toIntent(Settings.ACTION_APPLICATION_SETTINGS);
                break;
            case R.id.btn5:
                toIntent(Settings.ACTION_DEVICE_INFO_SETTINGS);
                break;
            case R.id.btn6:
                toIntent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
                break;
            case R.id.btn7:
                toIntent(Settings.ACTION_BLUETOOTH_SETTINGS);
                break;
            case R.id.btn8:
                toIntent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
                break;
/*            case R.id.btn9:
                //通用：但是针对跳转设置界面无效（可跳转设置的子界面）
                Bundle bundle = new Bundle();
                bundle.putBoolean("extra_prefs_show_skip", true);
                bundle.putBoolean("extra_prefs_show_button_bar", true);
                bundle.putBoolean("extra_prefs_set_next_text", true);
                bundle.putBoolean("extra_prefs_set_back_text", true);
                Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.btn10:
                //带有返回键的跳转：可用在部分以安卓为主板，自开发APP为Lancher，不带物理或者虚拟按键栏，
                //但又想使用系统自带的wifi功能模块（但是7.0的系统上依旧有左上角功能栏，可能会让客户跳转到其他地方去）
                Intent it = new Intent(Settings.ACTION_WIFI_SETTINGS);
                it.putExtra("extra_prefs_show_button_bar", true);
                it.putExtra("extra_prefs_set_back_text", "返回");
                it.putExtra("extra_prefs_set_next_text", "完成");
                startActivity(it);
                break;
            case R.id.btn11:
                //注意是这个：WifiManager.ACTION_PICK_WIFI_NETWORK (带有返回键，且只有wifi功能模块的，还可以在result中监听)
                Intent thatIntent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
                thatIntent.putExtra("only_access_points", true);
                thatIntent.putExtra("extra_prefs_show_button_bar", true);
                thatIntent.putExtra("wifi_enable_next_on_connect", true);
                startActivityForResult(thatIntent, 1);
                break;      */
            default:
                break;
        }
    }
}
